import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:kudos/config/widget_config.dart';
import '../../utils/kudo_colors.dart';
import '../../utils/image_resource_helper.dart';
import '../../utils/kudo_helper.dart';
import '../../state/person/persona_session_controller.dart';
import '../../state/person/persona_entity.dart';
import '../../state/person/persona_follow_controller.dart';
import '../../state/moment/kite_moment_controller.dart';
import '../../state/moment/kite_moment_entity.dart';
import '../../state/topic/kite_topic_controller.dart';
import '../../state/topic/kite_topic_entity.dart';
import '../../router/app_navigation_manager.dart';

/// 个人页面 - 使用非常规类名避免重复
class IdentityScreen extends StatefulWidget {
  const IdentityScreen({super.key});

  @override
  State<IdentityScreen> createState() => _IdentityScreenState();
}

class _IdentityScreenState extends State<IdentityScreen>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 2, vsync: this);

    // 延迟刷新数据，确保控制器已经初始化完成
    WidgetsBinding.instance.addPostFrameCallback((_) {
      _refreshUserData();
    });
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  /// 刷新用户数据
  void _refreshUserData() {
    final currentUser =
        PersonaSessionController.globalInstance.currentPersonaState.value;
    if (currentUser != null) {
      KiteMomentController.globalInstance.getUserKiteMoments(
        currentUser.uniqueIdentifier,
      );
      KiteTopicController.globalInstance.getUserDiscussedTopics();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: const BoxDecoration(
          image: DecorationImage(
            image: AssetImage('assets/images/chat_background.png'),
            fit: BoxFit.fill,
          ),
        ),
        child: SafeArea(
          bottom: false,
          child:
              PersonaSessionController.globalInstance.currentPersonaState
                          .reactiveValue(context) ==
                      null
                  ? _buildUnloggedState()
                  : _buildLoggedInContent(),
        ),
      ),
    );
  }

  /// 构建未登录状态
  Widget _buildUnloggedState() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        // 项目Logo
        Image.asset('assets/images/logo.png', width: 120.w, height: 120.h),
        SizedBox(height: 32.h),
        // 提示文本
        Text(
          'Welcome to Personal Center',
          style: TextStyle(
            fontSize: 24.sp,
            fontWeight: FontWeight.bold,
            color: KudoColors.black,
            fontFamily: GoogleFonts.lato().fontFamily,
          ),
          textAlign: TextAlign.center,
        ),
        SizedBox(height: 16.h),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 32.w),
          child: Text(
            'Please login to view your profile and activities',
            style: TextStyle(
              fontSize: 16.sp,
              color: KudoColors.black.withValues(alpha: 0.7),
              fontFamily: GoogleFonts.lato().fontFamily,
            ),
            textAlign: TextAlign.center,
          ),
        ),
        SizedBox(height: 48.h),
        // 登录按钮
        _buildLoginButton(),
      ],
    );
  }

  /// 构建登录按钮
  Widget _buildLoginButton() {
    return Container(
      width: 200.w,
      height: 48.h,
      decoration: BoxDecoration(
        color: KudoColors.yellow,
        borderRadius: BorderRadius.circular(24.r),
        boxShadow: [
          BoxShadow(
            color: KudoColors.black.withValues(alpha: 0.2),
            offset: const Offset(0, 4),
            blurRadius: 8,
          ),
        ],
      ),
      child:
          Text('Login')
              .fontSize(18.sp)
              .fontWeight(FontWeight.bold)
              .textColor(KudoColors.black)
              .fontFamily(GoogleFonts.lato().fontFamily)
              .center(),
    ).inkWell(onTap: _handleLoginTap);
  }

  /// 处理登录按钮点击
  void _handleLoginTap() {
    AppNavigationManager.navigateToCredentialEntry(context);
  }

  /// 构建已登录内容
  Widget _buildLoggedInContent() {
    // 确保在显示已登录内容时刷新数据
    WidgetsBinding.instance.addPostFrameCallback((_) {
      _refreshUserData();
    });

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        _buildPageHeader(),
        SizedBox(height: 24.h),
        _buildUserInfoCard(),
        SizedBox(height: 24.h),
        _buildTabSection(),
      ],
    );
  }

  /// 构建页面头部
  Widget _buildPageHeader() {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text('Personal Center')
              .fontSize(18.sp)
              .fontWeight(FontWeight.bold)
              .textColor(KudoColors.black)
              .fontFamily(GoogleFonts.lato().fontFamily),
          SvgPicture.asset(
            'assets/svg/setting.svg',
            width: 24.w,
            height: 24.h,
          ).inkWell(onTap: _handleSettingTap),
        ],
      ),
    );
  }

  /// 处理设置按钮点击
  void _handleSettingTap() {
    AppNavigationManager.navigateToSettingsScreen(context);
  }

  /// 构建用户信息卡片
  Widget _buildUserInfoCard() {
    final currentUser =
        PersonaSessionController.globalInstance.currentPersonaState.value;
    if (currentUser == null) return const SizedBox.shrink();

    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w),
      child: AspectRatio(
        aspectRatio: 343 / 170,
        child: Container(
          decoration: const BoxDecoration(
            image: DecorationImage(
              image: AssetImage('assets/images/personal_info_card.png'),
              fit: BoxFit.fill,
            ),
          ),
          child: Stack(
            children: [
              Padding(
                padding: EdgeInsets.all(16.w),
                child: Column(
                  children: [
                    _buildUserBasicInfo(currentUser),
                    SizedBox(height: 16.h),
                    _buildUserStats(currentUser),
                  ],
                ),
              ),
              Positioned(
                top: 0.h,
                right: 8.w,
                child: Transform.rotate(
                  angle: -0.1,
                  child: Container(
                    padding: EdgeInsets.symmetric(
                      horizontal: 12.w,
                      vertical: 4.h,
                    ),
                    decoration: BoxDecoration(
                      color: KudoColors.yellow,
                      borderRadius: BorderRadius.circular(12.r),
                    ),
                    child: Text('Mine')
                        .fontSize(12.sp)
                        .fontWeight(FontWeight.w900)
                        .fontFamily(
                          GoogleFonts.lato(
                            fontWeight: FontWeight.w900,
                          ).fontFamily,
                        )
                        .italic()
                        .textColor(Colors.white),
                  ).configWidget(borderRadius: 12.r),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 构建用户基本信息
  Widget _buildUserBasicInfo(PersonaEntity user) {
    return Row(
      children: [
        // 用户头像
        ClipRRect(
          borderRadius: BorderRadius.circular(32.r),
          child: Image.asset(
            user.avatarResourceUrl,
            width: 64.w,
            height: 64.h,
            fit: BoxFit.cover,
          ),
        ),
        SizedBox(width: 16.w),
        // 用户信息
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(user.displayAlias)
                  .fontSize(16.sp)
                  .fontWeight(FontWeight.bold)
                  .textColor(KudoColors.black),
              SizedBox(height: 4.h),
              Text(
                user.personalizedBio,
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                  fontSize: 12.sp,
                  color: KudoColors.black.withValues(alpha: 0.7),
                  fontFamily: GoogleFonts.lato().fontFamily,
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  /// 构建用户统计数据
  Widget _buildUserStats(PersonaEntity user) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        _buildStatItem(
          'Follow',
          PersonaFollowController.globalInstance
              .getFollowingCountState(user.uniqueIdentifier)
              .reactiveValue(context)
              .toString(),
        ),
        _buildStatItem(
          'Following',
          PersonaFollowController.globalInstance
              .getFollowerCountState(user.uniqueIdentifier)
              .reactiveValue(context)
              .toString(),
        ),
        _buildStatItem('Visitor', '24'), // 假数据
      ],
    );
  }

  /// 构建统计项
  Widget _buildStatItem(String label, String count) {
    return Column(
      children: [
        Text(count)
            .fontSize(18.sp)
            .fontWeight(FontWeight.bold)
            .textColor(KudoColors.black),
        SizedBox(height: 4.h),
        Text(
          label,
        ).fontSize(12.sp).textColor(KudoColors.black.withValues(alpha: 0.6)),
      ],
    );
  }

  /// 构建标签页部分
  Widget _buildTabSection() {
    return Expanded(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildTabBar(),
          SizedBox(height: 16.h),
          Expanded(child: _buildTabBarView()),
        ],
      ),
    );
  }

  /// 构建标签栏
  Widget _buildTabBar() {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Row(
        children: [
          _buildTabButton('Release', 0),
          SizedBox(width: 12.w),
          _buildTabButton('Topic Of Participation', 1),
        ],
      ),
    );
  }

  /// 构建标签按钮
  Widget _buildTabButton(String title, int index) {
    final isSelected = _tabController.index == index;
    return Text(title)
        .fontSize(20.sp)
        .fontWeight(FontWeight.w900)
        .textColor(
          isSelected
              ? KudoColors.black
              : KudoColors.black.withValues(alpha: 0.5),
        )
        .fontFamily(
          GoogleFonts.montserrat(fontWeight: FontWeight.w900).fontFamily,
        )
        .inkWell(
          onTap: () {
            setState(() {
              _tabController.animateTo(index);
            });
          },
        );
  }

  /// 构建标签页视图
  Widget _buildTabBarView() {
    return TabBarView(
      controller: _tabController,
      children: [_buildReleaseTab(), _buildTopicParticipationTab()],
    );
  }

  /// 构建发布标签页
  Widget _buildReleaseTab() {
    final currentUser =
        PersonaSessionController.globalInstance.currentPersonaState.value;
    if (currentUser == null) return const SizedBox.shrink();

    final userMoments = KiteMomentController.globalInstance.userMomentsState
        .reactiveValue(context);

    if (userMoments.isEmpty) {
      return Center(
        child: Text(
          'No releases yet',
          style: TextStyle(
            fontSize: 16.sp,
            color: KudoColors.black.withValues(alpha: 0.6),
            fontFamily: GoogleFonts.lato().fontFamily,
          ),
        ),
      );
    }

    return _buildTimelineMilestones(userMoments);
  }

  /// 构建时间线里程碑
  Widget _buildTimelineMilestones(List<KiteMomentEntity> moments) {
    return SingleChildScrollView(
      padding: EdgeInsets.only(
        left: 16.w,
        bottom: 100.h, // 添加底部间距，避免被导航栏挡住
      ),
      child: Column(
        children:
            moments.asMap().entries.map((entry) {
              final index = entry.key;
              final moment = entry.value;

              return IntrinsicHeight(
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: [
                    // 左侧时间线部分
                    SizedBox(
                      width: 40.w,
                      child: Column(
                        children: [
                          // 只显示时间，不显示圆点
                          Text(
                            _formatDate(moment.publishTimestamp),
                            style: TextStyle(
                              fontSize: 16.sp,
                              fontWeight: FontWeight.w900,
                              color: KudoColors.black,
                              fontFamily:
                                  GoogleFonts.montserrat(
                                    fontWeight: FontWeight.w900,
                                  ).fontFamily,
                            ),
                          ),
                          if (index < moments.length - 1)
                            Expanded(
                              child: SizedBox(
                                width: 2.w,
                                child: CustomPaint(
                                  painter: DashedLinePainter(
                                    color: KudoColors.inputBackground,
                                    strokeWidth: 2.0,
                                  ),
                                ),
                              ),
                            ),
                        ],
                      ),
                    ),
                    SizedBox(width: 16.w),
                    // 右侧内容部分
                    Expanded(
                      child: Padding(
                        padding: EdgeInsets.only(top: 26.h),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.end,
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            // 风筝时刻卡片
                            Expanded(flex: 2, child: _buildMomentCard(moment)),
                            SizedBox(width: 16.w),
                            // 评论数量
                            Expanded(
                              flex: 1,
                              child: Container(
                                margin: EdgeInsets.only(bottom: 10.h),
                                child: Text(
                                  'Total: ${moment.commentCount} Comments',
                                  style: TextStyle(
                                    fontSize: 12.sp,
                                    color: KudoColors.black,
                                    fontFamily: GoogleFonts.lato().fontFamily,
                                    fontWeight: FontWeight.w500,
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              );
            }).toList(),
      ),
    );
  }

  /// 构建动态卡片（参考设计图样式）
  Widget _buildMomentCard(KiteMomentEntity moment) {
    return GestureDetector(
      onTap:
          () =>
              AppNavigationManager.navigateToKiteMomentDetail(context, moment),
      child: Container(
        margin: EdgeInsets.only(bottom: 10.h),
        child: AspectRatio(
          aspectRatio: 167 / 196,
          child: ClipRRect(
            borderRadius: BorderRadius.circular(10.r),
            child: Stack(
              children: [
                // 背景图片（风筝时刻的图片或缩略图）
                Positioned.fill(
                  child:
                      moment.mediaResourceUrl.isNotEmpty
                          ? ImageResourceHelper.buildImageWidget(
                            imagePath:
                                moment.isVideoType &&
                                        moment.thumbnailResourceUrl != null
                                    ? moment.thumbnailResourceUrl!
                                    : moment.mediaResourceUrl,
                            fit: BoxFit.cover,
                            errorWidget: Container(
                              decoration: BoxDecoration(
                                gradient: LinearGradient(
                                  colors: [
                                    Colors.purple.withValues(alpha: 0.8),
                                    Colors.pink.withValues(alpha: 0.8),
                                    Colors.orange.withValues(alpha: 0.8),
                                  ],
                                  begin: Alignment.topLeft,
                                  end: Alignment.bottomRight,
                                ),
                              ),
                            ),
                          )
                          : Container(
                            decoration: BoxDecoration(
                              gradient: LinearGradient(
                                colors: [
                                  Colors.purple.withValues(alpha: 0.8),
                                  Colors.pink.withValues(alpha: 0.8),
                                  Colors.orange.withValues(alpha: 0.8),
                                ],
                                begin: Alignment.topLeft,
                                end: Alignment.bottomRight,
                              ),
                            ),
                          ),
                ),
                // 顶部蒙层和用户信息
                Positioned(
                  top: 0,
                  left: 0,
                  right: 0,
                  child: Container(
                    padding: EdgeInsets.all(12.w),
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [
                          Colors.black.withValues(alpha: 0.6),
                          Colors.transparent,
                        ],
                      ),
                    ),
                    child: Row(
                      children: [
                        // 用户头像
                        _buildAuthorAvatar(moment.authorIdentifier),
                        SizedBox(width: 8.w),
                        // 用户名
                        Expanded(
                          child: _buildAuthorName(moment.authorIdentifier),
                        ),
                        // 删除按钮
                        GestureDetector(
                          onTap: () => _showDeleteConfirmDialog(moment),
                          child: ImageResourceHelper.buildSvgIcon(
                            svgPath: 'assets/svg/delete.svg',
                            width: 22.w,
                            height: 22.w,
                            color: Colors.white,
                            errorWidget: Icon(
                              Icons.delete_outline,
                              color: Colors.white,
                              size: 16.sp,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                // 底部蒙层和详情文字
                Positioned(
                  bottom: 0,
                  left: 0,
                  right: 0,
                  child: Container(
                    padding: EdgeInsets.all(12.w),
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.bottomCenter,
                        end: Alignment.topCenter,
                        colors: [
                          Colors.black.withValues(alpha: 0.7),
                          Colors.transparent,
                        ],
                      ),
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        // 第一排文字 - 标题
                        Text(
                          moment.momentTitle.isNotEmpty
                              ? moment.momentTitle
                              : 'Weekend Recharge Plan:',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 14.sp,
                            fontWeight: FontWeight.bold,
                          ),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                        SizedBox(height: 2.h),
                        // 第二排文字 - 内容
                        Text(
                          moment.contentText.isNotEmpty
                              ? moment.contentText
                              : 'Kite + Sunshine = Full...',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 12.sp,
                          ),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  /// 格式化日期
  String _formatDate(DateTime date) {
    return '${date.month}.${date.day}';
  }

  /// 构建话题参与标签页
  Widget _buildTopicParticipationTab() {
    final discussedTopics = KiteTopicController
        .globalInstance
        .userDiscussedTopicsState
        .reactiveValue(context);

    if (discussedTopics.isEmpty) {
      return Center(
        child: Text(
          'No topic participation yet',
          style: TextStyle(
            fontSize: 16.sp,
            color: KudoColors.black.withValues(alpha: 0.6),
            fontFamily: GoogleFonts.lato().fontFamily,
          ),
        ),
      );
    }

    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Column(
        children:
            discussedTopics
                .map((topic) => _buildTopicParticipationItem(topic))
                .toList(),
      ),
    );
  }

  /// 构建话题参与项
  Widget _buildTopicParticipationItem(KiteTopicEntity topic) {
    return Container(
      margin: EdgeInsets.only(bottom: 12.h),
      child: AspectRatio(
        aspectRatio: 343 / 140,
        child: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(12.r),
            image: DecorationImage(
              image: AssetImage(topic.topicImageResource),
              fit: BoxFit.cover,
            ),
          ),
        ),
      ),
    ).inkWell(
      onTap:
          () => AppNavigationManager.navigateToKiteTopicDetail(context, topic),
    );
  }

  /// 显示删除确认对话框
  void _showDeleteConfirmDialog(KiteMomentEntity moment) {
    showDialog(
      context: context,
      barrierColor: Colors.black.withValues(alpha: 0.5),
      builder:
          (context) => Dialog(
            backgroundColor: Colors.transparent,
            child: Container(
              width: MediaQuery.of(context).size.width - 32.w,
              decoration: BoxDecoration(
                color: KudoColors.green,
                borderRadius: BorderRadius.circular(24.r),
              ),
              child: Stack(
                children: [
                  Padding(
                    padding: EdgeInsets.all(24.w),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        SizedBox(height: 20.h),
                        Text(
                          'Do You Want To Delete This Kite Moment?',
                          textAlign: TextAlign.center,
                          style: GoogleFonts.lato(
                            fontSize: 16.sp,
                            fontWeight: FontWeight.w400,
                            color: KudoColors.black,
                          ),
                        ),
                        SizedBox(height: 32.h),
                        Row(
                          children: [
                            Expanded(
                              child: Container(
                                height: 48.h,
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(20.r),
                                  border: Border.all(
                                    color: KudoColors.yellow,
                                    width: 2.w,
                                  ),
                                ),
                                child: TextButton(
                                  onPressed: () => Navigator.of(context).pop(),
                                  style: TextButton.styleFrom(
                                    shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(20.r),
                                    ),
                                  ),
                                  child: Text(
                                    'Cancel',
                                    style: GoogleFonts.lato(
                                      fontSize: 16.sp,
                                      fontWeight: FontWeight.bold,
                                      color: KudoColors.yellow,
                                    ),
                                  ),
                                ),
                              ),
                            ),
                            SizedBox(width: 16.w),
                            Expanded(
                              child: Container(
                                height: 48.h,
                                decoration: BoxDecoration(
                                  color: KudoColors.yellow,
                                  borderRadius: BorderRadius.circular(20.r),
                                  boxShadow: [
                                    BoxShadow(
                                      color: Colors.black.withValues(
                                        alpha: 0.3,
                                      ),
                                      blurRadius: 4.r,
                                      offset: Offset(0, 4.h),
                                    ),
                                  ],
                                ),
                                child: TextButton(
                                  onPressed: () {
                                    Navigator.of(context).pop();
                                    _handleDeleteMoment(moment);
                                  },
                                  style: TextButton.styleFrom(
                                    shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(20.r),
                                    ),
                                  ),
                                  child: Text(
                                    'Delete',
                                    style: GoogleFonts.lato(
                                      fontSize: 16.sp,
                                      fontWeight: FontWeight.bold,
                                      color: Colors.black,
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
    );
  }

  /// 处理删除风筝时刻
  void _handleDeleteMoment(KiteMomentEntity moment) {
    final success = KiteMomentController.globalInstance.deleteKiteMoment(
      moment.uniqueIdentifier,
    );

    if (success) {
      // 刷新当前用户的风筝时刻列表
      final currentUser =
          PersonaSessionController.globalInstance.currentPersonaState.value;
      if (currentUser != null) {
        KiteMomentController.globalInstance.getUserKiteMoments(
          currentUser.uniqueIdentifier,
        );
      }

      // 显示删除成功提示
      KudoToast.showSuccessToast(context, 'Kite moment deleted successfully');

      // 刷新页面状态
      setState(() {});
    } else {
      // 显示删除失败提示
      KudoToast.showErrorToast(context, 'Failed to delete kite moment');
    }
  }

  /// 构建作者头像
  Widget _buildAuthorAvatar(String authorId) {
    final users = PersonaEntity.getDefaultKiteUsers();
    final user = users.firstWhere(
      (u) => u.uniqueIdentifier == authorId,
      orElse: () => users.first,
    );
    return ImageResourceHelper.buildCircularAvatar(
      imagePath: user.avatarResourceUrl,
      radius: 14.r,
    );
  }

  /// 构建作者用户名
  Widget _buildAuthorName(String authorId) {
    final users = PersonaEntity.getDefaultKiteUsers();
    final user = users.firstWhere(
      (u) => u.uniqueIdentifier == authorId,
      orElse: () => users.first,
    );
    return Text(
      user.displayAlias,
      style: TextStyle(
        color: Colors.white,
        fontSize: 12.sp,
        fontWeight: FontWeight.w500,
        fontFamily: GoogleFonts.lato(fontWeight: FontWeight.w500).fontFamily,
      ),
    ).italic();
  }
}

/// 虚线绘制器 - 用于绘制时间线的虚线连接
class DashedLinePainter extends CustomPainter {
  final Color color;
  final double strokeWidth;
  final double dashWidth;
  final double dashSpace;

  DashedLinePainter({
    required this.color,
    this.strokeWidth = 2.0,
    this.dashWidth = 5.0,
    this.dashSpace = 3.0,
  });

  @override
  void paint(Canvas canvas, Size size) {
    final paint =
        Paint()
          ..color = color
          ..strokeWidth = strokeWidth
          ..style = PaintingStyle.stroke;

    double startY = 0;
    while (startY < size.height) {
      canvas.drawLine(
        Offset(size.width / 2, startY),
        Offset(size.width / 2, startY + dashWidth),
        paint,
      );
      startY += dashWidth + dashSpace;
    }
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => false;
}
